<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quản lý quảng cáo</title>
<link href="../Twitter_Bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../CSS/css_admin.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../CSS/validationEngine.jquery.css"/>

<script type="text/javascript" src="../Twitter_Bootstrap/js/jquery.js"></script>
<script type="text/javascript" src="../Twitter_Bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery.validationEngine.js"></script>
<script type="text/javascript" src="../Scripts/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="../Scripts/AdvertiseManagementJS.js"></script>


<style type="text/css">
<!--
#tbResult td,#tbResult th
{
	text-align:center;
}
-->
</style>
</head>

<body>
<div class="container" id="Container">
<!--Menu top -->
  <div id="menu">
  	<?php
		include("MainMenu.php");
		include("../Connections/connect_admin.php");
		
		$url="../Images/Advertisement/";
		$page=1;
		$recordPerPage=10;
		if(isset($_GET["page"]))
			{
				$page=intval($_GET["page"]);
			}
		$index=($page-1)*$recordPerPage;
		$keyword='';
		$pos=0;
		if(isset($_GET["keyword"]))
	  {
		$keyword=trim($_GET["keyword"]);
		$pos=intval($_GET["position"]);
		
		$query="SELECT * FROM advertisement a WHERE a.IsDeleted=0 AND (a.`Position`=$pos OR $pos=0) AND a.AdvertiseName LIKE '%$keyword%' ORDER BY a.CreatedDate DESC ";
	  }
	  else
	  {
		 $query="SELECT * FROM advertisement a WHERE a.IsDeleted=0 ORDER BY a.CreatedDate DESC ";
	  }
	  $sql=$query." Limit $index,$recordPerPage";
	  $result=mysql_query($sql);
	?>
    </div>
  </div>
  <div id="divContain">
  <!--Content -->
   <div class="divTitle"><span class="titlePage" >Quản lý quảng cáo</span></div>
  	<div style="padding-top:30px" >
     <form action="" method="get" id="formSearch" class="form-horizontal">
 		
        <input type="text" id="txtKeyword" name="keyword" placeholder="Từ khóa..." <?php if($keyword!='') echo "value='".$keyword."'";?>>
        <select name="position" id="cbxPosition">
        				<option value="0" <?php if($pos==0) echo "selected='selected'"; ?>>---Tất cả vị trí---</option>
                        <option value="1" <?php if($pos==1) echo "selected='selected'"; ?>>Header</option>
                        <option value="2" <?php if($pos==2) echo "selected='selected'"; ?>>Bên trái</option>
                        <option value="3" <?php if($pos==3) echo "selected='selected'"; ?>>Bên phải</option>
                        <option value="4" <?php if($pos==4) echo "selected='selected'"; ?>>Mục quảng cáo</option>
                        <option value="5" <?php if($pos==5) echo "selected='selected'"; ?>>Popup quảng cáo</option>
                        <option value="6" <?php if($pos==6) echo "selected='selected'"; ?>>Footer</option>
                        <option value="7" <?php if($pos==7) echo "selected='selected'"; ?>>Carousel</option>
        </select>
        <button class="btn" type="submit" id="btnSearch"><i class=" icon-search"></i> Tìm kiếm</button>
       
        
         <a type="button" class="btn btn-primary pull-right" id="btnAddAds" href="#updateAds" data-toggle="modal"><i class="icon-white icon-plus-sign"></i> Thêm quảng cáo</a>
    </form>
     <?php
	if(isset($_GET["e"]))
	{
		$error=intval($_GET["e"]);
		switch($error)
		{
			case 0:
	?>
    <div class="alert alert-success">
    	    <a class="close" data-dismiss="alert" href="#">&times;</a>
            <strong>Thêm mới quảng cáo THÀNH CÔNG</strong>
    </div>
    <?php
			break;
			case 1:
	?>
     <div class="alert alert-error">
    	    <a class="close" data-dismiss="alert" href="#">&times;</a>
            <strong>Thêm mới quảng cáo THẤT BẠI</strong>
    </div>
     <?php
	 		break;
			case 2:
	?>
     <div class="alert alert-success">
    	    <a class="close" data-dismiss="alert" href="#">&times;</a>
            <strong>Cập nhật quảng cáo THÀNH CÔNG</strong>
    </div>
     <?php
	 		break;
			case 3:
	?>
     <div class="alert alert-error">
    	    <a class="close" data-dismiss="alert" href="#">&times;</a>
            <strong>Cập nhật quảng cáo THẤT BẠI</strong>
    </div>
    <?php
			break;
		}	
		
	}
	?>
    
    <table class="table table-bordered table-striped  " id="tbResult" width="100%" border="0" cellspacing="0" cellpadding="0" >
  <tr>
  	<th scope="col" class="hide">Mã</th>
     <th scope="col">Hình ảnh</th>
    <th scope="col">Tên quảng cáo</th>
    <th scope="col">Mô tả</th>
    <th scope="col">Vị trí</th>
    <th scope="col">Link</th>
    <th scope="col">Loại file</th>
    <th scope="col"></th>
    <th scope="col"></th>
  </tr>
  <?php
  while($row=mysql_fetch_assoc($result))
  {
  ?>
  <tr>
  
    <td class="hide"><?php echo $row['AdvertiseID']; ?></td>
    <td>
    <?php
	switch($row['FileType'])
	{
		case 0:
		?>
         <img alt="" src="<?php echo $url.$row['FilePath']; ?>" width="100px"  />
        <?php
		break;
		case 1:
		?>
            <object width="100" height="100" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
    <param value="quangcao/qc1.swf" name="movie">
    <param value="high" name="quality">
    <embed width="100" height="100" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" quality="high" src="<?php echo $url.$row['FilePath']; ?>">
    </object>
        <?php
		break;
	}
	?>
    
   
    </td>
    <td><?php echo $row['AdvertiseName']; ?></td>
    <td><?php echo $row['Description']; ?></td>
    <td><?php 
	switch($row['Position'])
	{
		case 1:
		echo "<label id='".$row['Position']."'>Header</label>";
		break;
		case 2:
		echo "<label id='".$row['Position']."'>Bên trái</label>";
		break;
		case 3:
		echo "<label id='".$row['Position']."'>Bên phải</label>";
		break;
		case 4:
		echo "<label id='".$row['Position']."'>Mục quảng cáo</label>";;
		break;
		case 5:
		echo "<label id='".$row['Position']."'>Popup</label>";
		break;
		case 6:
		echo "<label id='".$row['Position']."'>Footer</label>";
		break;
		case 7:
		echo "<label id='".$row['Position']."'>Carousel</label>";
		break;
	}
	?></td>
    <td><?php echo $row['Link']; ?></td>
    <td><?php  if($row['FileType']==0){echo "Hình ảnh";}else{echo "Flash";} ?></td>
    <td><a href="#" title="Xóa" class="delete"><img src="../Images/Icons/delete.png" alt="delete" /></a></td>
    <td><a href="#updateAds" data-toggle="modal" title="Sửa" class="update"><img src="../Images/Icons/page_edit.png" alt="update" /></a></td>
   
  </tr>
  <?php }?>
</table>
	    <div class="pagination pull-right">
   <?php require("process/funcPaging.php");
			
			if(isset($_GET["keyword"]))
			{
				$keyword=$_GET["keyword"];
				$pos=intval($_GET["position"]);
				$link="Advertisement.php?keyword=".$keyword."&position=".$pos."&";
			}
			else
			{	
				$link="Advertisement.php?";
			}
			$resAll=mysql_query($query);
			$total=mysql_num_rows($resAll);
			
			Paging($total,$page,5,$recordPerPage,$link);
 		?>  
    </div>
	</div>
  <!--footer -->
  </div>
  <div id="footer">
     <?php
     	include("Footer.php");
	 ?>
  </div>
</div>

<!---------------------------Popup Thêm/Cập nhật quảng cáo----------------------------->
    <div class="modal hide fade"  id="updateAds">
    <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3></h3>
    </div>
    <form action="process/Advertisement_process.php" method="post" enctype="multipart/form-data" id="formAds" style="margin-bottom:0px">
    <div class="modal-body">
    <p>
    		<input type="hidden" name="task" id="task" />
          
        	<table width="100%" border="0" cellspacing="0" cellpadding="0">
            	<tr class="hide">
                    <td>Mã quảng cáo</td>
                    <td><input name="advid" type="text" id="txtAdsID" /></td>
                  </tr>
            	<tr>
                    <td>Tên quảng cáo:</td>
                    <td><input name="advname" type="text" id="txtAdsName" class="validate[required]" /></td>
                  </tr>
                  <tr>
                    <td>Vị trí:</td>
                    <td>
                    <select name="position" id="cbxPositionUPD" class="validate[required]">
        				<option value="">---vị trí---</option>
                        <option value="1">Header</option>
                        <option value="2">Bên trái</option>
                        <option value="3">Bên phải</option>
                        <option value="4">Mục quảng cáo</option>
                        <option value="5">Popup quảng cáo</option>
                        <option value="6">Footer</option>
                        <option value="7">Carousel</option>
        			</select>
                    </td>
                  </tr>
                  <tr>
                    <td>Link:</td>
                    <td><input name="link" type="text" id="txtLink" class="validate[required,custom[url]]"/></td>
                  </tr>
                  <tr>
                    <td>File Upload:</td>
                    <td><input name="updfile" type="file" id="updfile" /></td>
                  </tr>
                   <tr>
                    <td>Mô tả:</td>
                    <td><textarea id="txtDescription" rows="3" name="description"></textarea></td>
                  </tr>
              </table>

       
    </p>
    </div>
    <div class="modal-footer">
    <a href="#" class="btn" data-dismiss="modal">Đóng lại</a>
    <button type="submit" class="btn btn-primary" id="btnSave">Cập nhật</button>
    </div>
     </form>
     <script>
		//-----------------------Validation----------------------------------
			$(document).ready(function(){
							   $("#formAds").validationEngine();
							   });
		</script>
    </div>
</body>
</html>
